/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            transferPartnerGoodsInfo: {
                ppId:'',
                products: [],
                remark: '',
                shopId: ''
            }
        },
        _initMethod: function () {
            $that.transferPartnerGoodsInfo.ppId = vc.getParam('ppId');
            $that.transferPartnerGoodsInfo.shopId =  vc.getCurrentCommunity().shopId;

        },
        _initEvent: function () {
            vc.on('transferPartnerGoods', 'chooseParknerGoods', function (_product) {
                let _products = $that.transferPartnerGoodsInfo.products;
                let _hasIn =false;
                _products.forEach(_p=>{
                    if(_product.valueId == _p.valueId){
                        _hasIn =true;
                    }
                });
                if(_hasIn){
                    vc.toast('请勿重复选择');
                    return;
                }
                _products.push(_product);
            });
        },
        methods: {
            _doInoutOrder: function () {
                let _products = $that.transferPartnerGoodsInfo.products;
                if (_products.length < 1) {
                    vc.toast('请选择商品');
                    return;
                }
                vc.http.apiPost(
                    '/partner.syncPartnerGoods',
                    JSON.stringify($that.transferPartnerGoodsInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast(_json.msg);
                            vc.goBack();
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _openAddShopHouseModal: function () {
                vc.emit('chooseParknerGoods', 'openChooseProductModel', {
                    ppId:$that.transferPartnerGoodsInfo.ppId
                });
            },
            _goBack: function () {
                vc.goBack();
            },
            _deleteProduct: function (_inoutOrderProduct) {
                let _products = $that.transferPartnerGoodsInfo.products;
                let index = _products.indexOf(_inoutOrderProduct);
                if (index > -1) {
                    _products.splice(index, 1);
                }
            },
        }
    });
})(window.vc);
